package de.clapp.client.values;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Methods
{
    @SuppressWarnings("unchecked")
   public static <T> T objectCopy(final T item)
   {
       try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
       final ObjectOutputStream oos = new ObjectOutputStream(baos);)
       {
           oos.writeObject(item);
           // Falls Daten im Puffer gehalten werden
           oos.flush();
           try (final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));)
           {
               return (T) ois.readObject();
           }
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }
       return null;
   }
}
